class Solution {
    public boolean isHappy(int n) {
        int slow = n ;
        int fast = getSum(n) ;
        while(slow != fast){
            slow = getSum(slow);
            fast = getSum(getSum(fast));
        }
        return slow == 1 ;
    }
    public int getSum(int num){
        int sum = 0 ;
        while(num != 0){
            int tmp = num % 10 ;
            sum += tmp * tmp ;
            num /= 10 ;
        }
        return sum ;
    }
}